package com.ll.agent.visitor;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;

import java.lang.reflect.Method;

import static org.objectweb.asm.Opcodes.ASM7;

/**
 * @description:
 * @author: LiuLei
 * @create: 2024-07-18
 **/
public class MyClassVisitor extends ClassVisitor {

    public MyClassVisitor(ClassVisitor classVisitor) {
        super(ASM7, classVisitor);
    }


    @Override
    public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
        MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
        // 只转换 foo 方法
        if ("say".equals(name)) {
            return new MyMethodVisitor(mv, access, name, descriptor);
        }
        return mv;
    }
}
